//
//  MineView.m
//  Project_B
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 ZY. All rights reserved.
//

#import "MineView.h"

@implementation MineView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubViews];
    }
    return self;
}
- (void)createSubViews
{
    
    self.bgImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT/3)];
    self.bgImage.backgroundColor = [UIColor colorWithRed:0.316 green:0.769 blue:0.830 alpha:1.000];
    self.bgImage.image = [UIImage imageNamed:@"NightImage.jpg"];
    self.bgImage.contentMode = UIViewContentModeScaleAspectFill;
//    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(bgAction)];
    self.bgImage.userInteractionEnabled = YES;
//    [self.bgImage addGestureRecognizer:tap1];
    [self addSubview:self.bgImage];


    
//    self.PicImage = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/2-40*ADAPT_WIDTH, self.frame.size.height-80*ADAPT_HEIGHT, 80*ADAPT_WIDTH, 80*ADAPT_HEIGHT)];
//    self.PicImage.backgroundColor = [UIColor colorWithRed:0.135 green:0.830 blue:0.190 alpha:1.000];
//    self.PicImage.layer.masksToBounds = YES;
//    self.PicImage.layer.cornerRadius = 40;
//    self.PicImage.userInteractionEnabled = YES;
//    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isExite"] length] == 0) {
//        self.PicImage.image = [UIImage imageNamed:PLACEHOLDER_IMAGE];
//    }else{
//        self.PicImage.image = [self getPhotoFromName:@"public.image"];
//    }
//    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(picAction)];
//    [self.PicImage addGestureRecognizer:tap];
    [self addSubview:self.PicImage];


}
//#pragma mark === 将图片存入沙盒
//-(BOOL) setPhotoToPath:(UIImage *)image isName:(NSString *)name
//{
//    //此处首先指定了图片存取路径（默认写到应用程序沙盒 中）
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
//    
//    //并给文件起个文件名
//    NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:name];
//    BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];
//    if (blHave) {
//        NSLog(@"already have");
//        //delete
//        [self deleteFromName:name];
//    }
//    NSData *data = UIImagePNGRepresentation(image);
//    BOOL result = [data writeToFile:uniquePath atomically:YES];
//    if (result) {
//        //NSLog(@"success");
//        return YES;
//    }else {
//        //NSLog(@"no success");
//        return NO;
//    }
//}
//#pragma mark === 根据名字取图片
//- (UIImage *)getPhotoFromName:(NSString *)name
//{
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
//    //NSFileManager* fileManager=[NSFileManager defaultManager];
//    NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:name];
//    BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];
//    if (!blHave) {
//        return nil;
//    }else
//    {
//        NSData *data = [NSData dataWithContentsOfFile:uniquePath];
//        UIImage *img = [[UIImage alloc] initWithData:data];
//        // NSLog(@" have");
//        return img;
//    }
//}
//#pragma mark === 根据名字删除
//-(BOOL)deleteFromName:(NSString *)name
//{
//    NSFileManager* fileManager=[NSFileManager defaultManager];
//    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES);
//    //文件名
//    NSString *uniquePath=[[paths objectAtIndex:0] stringByAppendingPathComponent:name];
//    BOOL blHave=[[NSFileManager defaultManager] fileExistsAtPath:uniquePath];
//    if (!blHave) {
//        //NSLog(@"no  have");
//        return NO;
//    }else {
//        //NSLog(@" have");
//        BOOL blDele= [fileManager removeItemAtPath:uniquePath error:nil];
//        if (blDele) {
//            //NSLog(@"dele success");
//            return YES;
//        }else {
//            //NSLog(@"dele fail");
//            return NO;
//        }
//    }
//}
//#pragma mark === 头像点击方法
//- (void)picAction
//{
//    self.pick1 = [[UIImagePickerController alloc] init];
//    self.pick1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//    self.pick1.allowsEditing = YES;
//    self.pick1.delegate = self;
//    [self presentViewController:self.pick1 animated:YES completion:^{
//        
//    }];
//}
//#pragma mark === 进入相册方法
//-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
//{
//    if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isExite"] isEqualToString:@"YES"])
//    {
//        
//        [[NSUserDefaults standardUserDefaults] setValue:[NSString stringWithFormat:@"%d",![self deleteFromName:@"public.image"]] forKey:@"isExite"];
//    }
//    NSLog(@"info = %@",info);//打印是一个字典
//    //根据字典中key为UIImagePickerControllerOriginalImage来获取图片
//    UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
//    
//    self.PicImage.image = image;
//    [[NSUserDefaults standardUserDefaults] setValue:[NSString stringWithFormat:@"%d",[self setPhotoToPath:image isName:@"public.image"]] forKey:@"isExite"];
//    
//    
//    [picker dismissViewControllerAnimated:YES completion:^{
//        
//        
//    }];
//}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
